<?php
session_start();

// inloggegevens
$username = "root";
$password = "usbw";
$database = "guitig";

// Connect aan de database
mysql_connect("localhost", $username, $password);
mysql_select_db($database) or die("<head><script type=\"text/javascript\">alert('Unable to select database!');history.back();</script></head>");

if (isset($_GET["week"])) { $weeknr = $_GET["week"]; }

	$helenaam = "Meneer Beheer";
	//$helenaam = mysql_result($RESULT, 0, "voornaam")." ".mysql_result($RESULT, 0, "tussenvoegsel")." ".mysql_result($RESULT, 0, "achternaam");
	//$klas = mysql_result($RESULT, 0, "klas");

	?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>iCUP - Beheer</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="Buttons.css" />

<script type="text/javascript" src="funcs.js"></script>

</head>
<?php


	$QUERY = "
	SELECT dag, uur 
	FROM studieuur";
	$resultuurnr = mysql_query($QUERY);
	
	$QUERY = "
	SELECT DISTINCT week 
	FROM studieuur";
	$resultweeknr = mysql_query($QUERY);


?><body>
<div id="div1">
	<div id="div2"><img src='pics/logo.png'><br />
		Welkom <?php echo $helenaam;?>. <br /><br />
		Volgende weken zijn beschikbaar:<br />
		<div id="wk_div">
			<table align="center">
				<tr>
<?php


for($i = 0; $i < mysql_num_rows($resultuurnr); $i++)
{


?>					<td><a id="wk_<?php print(mysql_result($resultuurnr, $i, "dag") . mysql_result($resultuurnr, $i, "uur"));?>" onclick="getweeks('<?php print(mysql_result($resultuurnr, $i, "dag") . mysql_result($resultuurnr, $i, "uur"));?>')" href="#" class="wk_button"><?php print(mysql_result($resultuurnr, $i, "dag") . mysql_result($resultuurnr, $i, "uur"));?></a></td>
<?php


}



?>
				</tr>
			</table>
			<table align="right">
				<tr>
					<td><a onclick="addweek();" class="actionbutton"><img src="pics/addweek.png" /></a></td>
					<td><a onclick="delweek();" class="actionbutton"><img src="pics/delweek.png" /></a></td>
					<td><a onclick="editweek();" class="actionbutton"><img src="pics/editweek.png" /></a></td>
				</tr>
			</table><br/>
			<table align="center">
				<tr>
<?php


for($i = 0; $i < mysql_num_rows($resultweeknr); $i++)
{


?>					<td><a id="wk_<?php print(mysql_result($resultweeknr, $i, "week"));?>" onclick="getweeks('<?php print(mysql_result($resultweeknr, $i, "week"));?>')" href="#" class="wk_button"><?php print(mysql_result($resultweeknr, $i, "week"));?></a></td>
<?php


}



?>
				</tr>
			</table>
			<table align="right">
				<tr>
					<td><a onclick="addweek();" class="actionbutton"><img src="pics/addweek.png" /></a></td>
					<td><a onclick="delweek();" class="actionbutton"><img src="pics/delweek.png" /></a></td>
					<td><a onclick="editweek();" class="actionbutton"><img src="pics/editweek.png" /></a></td>
				</tr>
			</table>
		</div>
	</div>
	<table width="100%">
		<tr><td align="center"><a onclick="editweekdefault();" class="menubutton">Beheer standaard week</a></td></tr>
		<tr><td align="center"><a onclick="editpupils();" class="menubutton">Beheer leerlingen</a></td></tr>
		<tr><td align="center"><a href="beheerfuncs.php?logout" class="menubutton">Uitloggen</a></td></tr>
	</table>
</div>
<div id="content">
<?php

if (isset($_GET["week"])) { $weeknr = $_GET["week"]; } else { $weeknr = 0; }
$naam = "";

$Qstudieuurvanleerling = "
	SELECT studieuur 
	FROM studieuurklas 
	WHERE studieuur  LIKE '$weeknr%'
	";
$resultheader = mysql_query($Qstudieuurvanleerling);
$columns = mysql_numrows($resultheader);



	for($i=0; $i<$columns; $i++)
	{
		$header = mysql_result($resultheader, $i, "studieuur"); // de manier waarop je info uit de db haalt
		$displayheader = $header;
		$Qplaatsvanstudie = "SELECT plaatsnr FROM studieuurplaats";

		$Qdata = "SELECT plaatsnr, lokaal, docentid, vak FROM plaats WHERE plaatsnr IN ($Qplaatsvanstudie)";

		$resultdata = mysql_query($Qdata);
		$rows = mysql_numrows($resultdata);



		print("
<div style='position: absolute; width: 100px; top: 100px; left: "); print(400+105*$i); print("px'>
	<div class=uur>$displayheader</div>
		");



		for($j=0; $j<$rows; $j++)
		{
			$plaatsnr = mysql_result($resultdata, $j, "plaatsnr");
			$datavak = mysql_result($resultdata, $j, "vak");
			$datadocentid = mysql_result($resultdata, $j, "docentid");
			$datalokaal = mysql_result($resultdata, $j, "lokaal");



			print("
	<div id='$i.$j' class=plaats onclick='document.getElementById(\"rb$i"."_$j\").checked=true; for(i=0; i<$rows; i++) { document.getElementById(\"$i.\"+i).style.backgroundColor=\"#ffffff\"; } style.backgroundColor=\"#66ee11\";
loadXMLDoc(\"intekenen.php?id=\" + \"$plaatsnr\" + \"&uur=\" + \"$header\"); alert(\"intekenen.php?id=\" + \"$plaatsnr\" + \"&uur=\" + \"$header\");'>$datavak $datadocentid $datalokaal</div>
	<input id='rb$i"."_$j' type='radio' style='display: none'>
			");



		}



		print("
</div>
		");



	}



	print("
	<!-- this.id.charAt(0)+\".\"+i	 :	 geeft de (x-coordinaat van de) naam van de divs die hij wit moet maken, maar door de charAt() kunnen er maximaal 10 divs (op de x-as) komen.-->
<!-- Ik ga er niet vanuit dat er meer dan 10 studieuren in 1 week zitten, maar toch...-->

	");



mysql_close();

?>
</div>
</body>
</html>
